package com.ys.erp.entity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ys.erp.entity.data.bean.Employee;
import com.ys.erp.entity.mapper.EmployeeMapper;
import com.ys.erp.entity.service.IEmployeeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lwj
 * @date 2023/4/8
 */

@Service
@RequiredArgsConstructor
public class IEmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Override
    public Map<Long, Employee> getEmpMapByEmpIdList(List<Long> empList) {
        if (CollectionUtils.isEmpty(empList)) {
            return Collections.emptyMap();
        }
        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        employeeQueryWrapper.lambda().in(Employee::getId, empList);
        List<Employee> employeeList = this.list(employeeQueryWrapper);
        return employeeList.stream().collect(Collectors.toMap(Employee::getId, Function.identity()));
    }

    @Override
    public Employee getEmpByPhone(String phone) {
        QueryWrapper<Employee> empQw = new QueryWrapper<>();
        empQw.lambda().eq(Employee::getPhone, phone);
        return this.getOne(empQw);
    }
}
